package com.fantastic.web.controller.admin;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.model.pojo.zjs.Member;
import com.fantastic.model.pojo.zjs.MemberVariety;
import com.fantastic.service.zjs.MemberService;
import com.fantastic.service.zjs.MemberVarietyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/6/4 16:15
 * @description: 会员卡和菜品关联表请求控制器
 */
@RestController
@RequestMapping("/memberVariety")
public class MemberVarietyControllerAdmin {

    @Resource
    private MemberVarietyService memberVarietyService;

    /**
     * 查询会员卡和菜品关联信息
     *
     * @param memberVariety
     * @param pageSize
     * @param pageNum
     * @return
     */
    @PostMapping("/listMemberVariety")
    public ResultData listMemberVariety(MemberVariety memberVariety,
                                        @RequestParam(name="page",
                                                defaultValue = "1") int pageNum,
                                        @RequestParam(name="limit",defaultValue = "9999999") int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<MemberVariety> list = memberVarietyService.listMemberVariety(memberVariety);
        PageInfo<MemberVariety> pageInfo = new PageInfo<>(list);
        return new ResultData(RespStatusInfo.OK, pageInfo);
    }

    /**
     * 查询单个会员卡和菜品关联信息
     *
     * @param varietyId
     * @param memberId
     * @return
     */
    @PostMapping("/getMemberVariety")
    public ResultData getMemberVariety(Integer memberId, Integer varietyId) {
        return new ResultData(RespStatusInfo.OK, memberVarietyService.getMemberVariety(memberId, varietyId));
    }

    /**
     * 添加会员卡和菜品关联信息
     *
     * @param memberVariety
     * @return
     */
    @PostMapping("/insertMemberVariety")
    public ResultData insertMemberVariety(MemberVariety memberVariety) {
        return new ResultData(RespStatusInfo.OK, memberVarietyService.insertMemberVariety(memberVariety));
    }

    /**
     * 修改会员卡和菜品关联信息
     *
     * @param memberVariety
     * @return
     */
    @PutMapping("/updateMemberVariety")
    public ResultData updateMemberVariety(MemberVariety memberVariety) {
        return new ResultData(RespStatusInfo.OK, memberVarietyService.updateMemberVariety(memberVariety));
    }

    /**
     * 删除会员卡和菜品关联信息
     *
     * @param varietyId
     * @param memberId
     * @return
     */
    @DeleteMapping("/deleteMemberVariety")
    public ResultData deleteMemberVariety(Integer memberId, Integer varietyId) {
        return new ResultData(RespStatusInfo.OK, memberVarietyService.deleteMemberVariety(memberId, varietyId));
    }


}
